package com.bl.commons.models;

import com.bl.commons.enums.RespCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import javax.xml.ws.Response;
import java.io.Serializable;

/**
 * 返回结果
 *
 * @author bl
 * @date 2023/10/16
 */
@Data
@ApiModel("统一返回对象")
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("(统一返回)数据结果")
    private T data;

    @ApiModelProperty("(统一返回)成功状态")
    @Builder.Default
    private boolean success = true;

    @ApiModelProperty("(统一返回)提示消息")
    @Builder.Default
    private String message = "成功";

    @ApiModelProperty("(统一返回)状态码")
    @Builder.Default
    private RespCodeEnum code ;


    public Result(T data, String message, RespCodeEnum code) {
        this.data = data;
        this.message = message;
        this.code = code;
    }

    public static <T> Result<T> success(T data,String msg){
        return new Result<T>(data,msg,RespCodeEnum.SUCCESS);
    }

    public static <T> Result<T> fail(T data,String msg,RespCodeEnum codeEnum){
        return new Result<T>(data,msg,codeEnum);
    }
}
